//package com.xyh.transaction.controller;
//
//import com.alibaba.fastjson.JSON;
//import com.xyh.transaction.entity.dto.MessagesDTO;
//import com.xyh.transaction.entity.dto.RequestMessageDto;
//import com.xyh.transaction.entity.dto.ResponseMessageDto;
//import com.xyh.transaction.utils.HttpUtil;
//import io.swagger.annotations.Api;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.messaging.handler.annotation.MessageMapping;
//import org.springframework.messaging.handler.annotation.SendTo;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//
//import java.util.ArrayList;
//
//@Slf4j
//@Api(tags = "WebSocket接口管理")
//@Controller
//@RequestMapping("socket")
//public class WebSocketController {
//
//
//    private final ArrayList<MessagesDTO> messagesDTOArrayList = new ArrayList<>();
//
//    @MessageMapping("/chat")
//    @SendTo("/topic/messages") // @SendTo 主要用于将消息广播到所有订阅指定主题的客户端
//    public String handleChatMessage(String message) {
//        log.info("接收到websocket消息：{}", message);
//        String responseMessage = null;
//        try {
//            String authorizationHeader = "Bearer irvhOUpiUlGSUbKurNzX:fcOEbYOfEurFrEkXsxsR";
//            String response = "";
//
//            // 测试POST请求
//            RequestMessageDto requestMessageDto = new RequestMessageDto();
//            requestMessageDto.setModel("general");
//            requestMessageDto.setStream(false);
//            MessagesDTO messagesDTO = new MessagesDTO();
//            messagesDTO.setRole("user");
//            messagesDTO.setContent(message);
//            messagesDTOArrayList.add(messagesDTO);
//            requestMessageDto.setMessages(messagesDTOArrayList);
//            response = HttpUtil.sendPost("https://spark-api-open.xf-yun.com/v1/chat/completions", JSON.toJSONString(requestMessageDto), authorizationHeader);
////            System.out.println("POST Response: " + response);
//            responseMessage = JSON.parseObject(response, ResponseMessageDto.class).getChoices().get(0).getMessage().getContent();
//            MessagesDTO messagesDTO1 = new MessagesDTO();
//            messagesDTO1.setRole("assistant");
//            messagesDTO1.setContent(responseMessage);
//            messagesDTOArrayList.add(messagesDTO1);
//            log.info("星火大模型返回消息：{}", responseMessage);
//        } catch (Exception e) {
//            responseMessage = "访问星火大模型失败，请稍后再试或联系管理员";
//            log.info("访问星火大模型异常{}", e.getMessage());
//        }
//
//        return responseMessage;
//    }
//}
